package cool.taomu.toolkit

import cool.taomu.toolkit.Context
import cool.taomu.toolkit.TaomuConfigure
import cool.taomu.toolkit.TaomuGuice
import cool.taomu.toolkit.TaomuGuiceServiceLoader
import cool.taomu.toolkit.crypto.Base64
import cool.taomu.toolkit.crypto.ICrypto
import com.google.inject.Module

class Taomu {

    def static getInjector() {
        run(new Base64())
    }

    def static run() {
        run(new Base64())
    }

    def static run(Module ... module) {
        run(new Base64(), module)
    }

    def static run(ICrypto crypto, Module ... module) {
        val TaomuConfigure config = new TaomuConfigure(crypto)
        config.loadConfig
        var injector = TaomuGuice.createInjector(config, module)
        TaomuGuiceServiceLoader.loadIPlatform(injector, config)
        var context = injector.getInstance(Context);
        var cinjector = context.injectorSupplier.get()
        return cinjector
    }
}
